package me.dz.dreamcleaner.manager;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

import static me.dz.dreamcleaner.DreamCleaner.*;

public class WorldManager {
    public static Collection<Entity> getNearbyEntities(Location location, double aoe){
        if (location != null){
            World world = location.getWorld();
            if (world != null){
                if (uranium){
                    ArrayList<Entity> entities = new ArrayList<>();
                    for (Entity entity : world.getEntities()){
                        if (entity.getLocation().distance(location) <= aoe){
                            entities.add(entity);
                        }
                    }
                    return entities;
                }else {
                    return world.getNearbyEntities(location,aoe,aoe,aoe);
                }
            }
        }
        return new ArrayList<>();
    }

    public static HashMap<World,ArrayList<Entity>> getEntities(ArrayList<String> worlds,boolean b){
        HashMap<World, ArrayList<Entity>> map = new HashMap<>();
        for (World world : Bukkit.getWorlds()){
            if (canClear(world,worlds,b)){
                map.put(world,new ArrayList<>(world.getEntities()));
            }
        }
        return map;
    }

    public static String getOnline(){
        return Bukkit.getOnlinePlayers().size() + "";
    }

    public static String getPlayers(){
        int i = 0;
        for (Player player : Bukkit.getOnlinePlayers()){
            if (player.isOp())continue;
            i++;
        }
        return i + "";
    }

    public static boolean canClear(World world,ArrayList<String> list,boolean b){
        if (list.contains(world.getName())){
            return b;
        }else {
            return !b;
        }
    }
}
